package org.txazo.blog.commons.io;

import org.txazo.blog.commons.io.base.Writer;

public class StringLineWriter implements Writer {

	private StringBuilder sb = null;

	/** 第一行写入标识 */
	private boolean firstWriteFlag = true;
	/** 默认初始大小 */
	private static int defaultInitCapacity = 4096;
	/** 分隔符 */
	private static String lineSeparator = System.getProperty("line.separator");

	public StringLineWriter() {
		this(defaultInitCapacity);
	}

	public StringLineWriter(int initCapacity) {
		sb = new StringBuilder(initCapacity);
	}

	@Override
	public void write(String str) {
		if (firstWriteFlag) {
			firstWriteFlag = false;
		} else {
			sb.append(lineSeparator);
		}
		sb.append(str);
	}

	@Override
	public StringBuilder getOut() {
		return sb;
	}

}
